package com.orchard.xpz.controller.incomeInfo;

import com.orchard.xpz.entity.GardenWork.GardenWork;
import com.orchard.xpz.entity.IncomeInfo.IncomeInfo;
import com.orchard.xpz.service.incomeInfo.IncomeInfoService;
import com.orchard.xpz.utils.PageResultData;
import com.orchard.xpz.utils.R;
import com.orchard.xpz.utils.UserRuntime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @TaskCode:
 * @description:
 * @author: minshuai.chen
 * @create: 2022/4/19 11:08
 **/
@RestController
@RequestMapping("/incomeInfo")
public class IncomeInfoController {

    @Autowired
    private IncomeInfoService incomeInfoService;

    @RequestMapping("/getPageList")
    public R<PageResultData<IncomeInfo>> getPageList(@RequestBody IncomeInfo gardenPlot){
        return R.success(incomeInfoService.getPageList(gardenPlot));
    }

    @RequestMapping("/saveOrUpdate")
    public R<String> saveOrUpdate(@RequestBody IncomeInfo gardenPlot){
        Thread t = Thread.currentThread();
        System.out.println(t+"==" +t.getId()+"++"+ t.getId());
        System.out.println(UserRuntime.getUser());
        if (incomeInfoService.saveOrUpdate(gardenPlot)){
            return R.success("success");
        }else{
            return R.fail("error");
        }
    }

    @RequestMapping("/delete")
    public R<String> delete(@RequestParam("id") String id){
        if (incomeInfoService.deltePlot(id)){
            return R.success("success");
        }else{
            return R.fail("error");
        }
    }
}
